package com.sxjh.controller.pub;

import cn.hutool.extra.cglib.CglibUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sxjh.common.BaseController;
import com.sxjh.common.Constant;
import com.sxjh.common.Result;
import com.sxjh.entity.Suppliers;
import com.sxjh.entity.result.SupplierListResult;
import com.sxjh.service.SuppliersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/supplier")
@Api(tags = "供应商-客户-承运商")
public class SupplierController extends BaseController {

  @Autowired
  private SuppliersService suppliersService;

  /**
   * 供应商
   */
  @GetMapping
  @ApiOperation("供应商")
  public Result<List<SupplierListResult>> list() {
    List<Suppliers> list = suppliersService.list(new LambdaQueryWrapper<Suppliers>()
            .eq(Suppliers::getStatus, Constant.YES).eq(Suppliers::getType, 2));
    List<SupplierListResult> results = CglibUtil.copyList(list, SupplierListResult::new);
    return Result.ok(results);
  }

  /**
   * 客户
   */
  @GetMapping("/kh")
  @ApiOperation("客户")
  public Result<List<SupplierListResult>> list2() {
    List<Suppliers> list = suppliersService.list(new LambdaQueryWrapper<Suppliers>()
            .eq(Suppliers::getStatus, Constant.YES).eq(Suppliers::getType, 1));
    List<SupplierListResult> results = CglibUtil.copyList(list, SupplierListResult::new);
    return Result.ok(results);
  }

  /**
   * 承运商
   */
  @GetMapping("/cys")
  @ApiOperation("承运商")
  public Result<List<SupplierListResult>> list3() {
    List<Suppliers> list = suppliersService.list(new LambdaQueryWrapper<Suppliers>()
            .eq(Suppliers::getStatus, Constant.YES).eq(Suppliers::getType, 3));
    List<SupplierListResult> results = CglibUtil.copyList(list, SupplierListResult::new);
    return Result.ok(results);
  }

  /**
   * 所有供应商客户
   */
  @GetMapping("/all")
  @ApiOperation("所有供应商/客户")
  public Result<List<SupplierListResult>> list4() {
    List<Suppliers> list = suppliersService.list(new LambdaQueryWrapper<Suppliers>()
            .eq(Suppliers::getStatus, Constant.YES));
    List<SupplierListResult> results = CglibUtil.copyList(list, SupplierListResult::new);
    return Result.ok(results);
  }

  /**
   * 根据物料大类，获取公司
   */
  @GetMapping("/gss/{id}")
  @ApiOperation("根据物料大类获取公司")
  Result<List<SupplierListResult>> list4(@PathVariable("id") Integer id) {
    List<SupplierListResult> list = suppliersService.getComputer(id);
    return Result.ok(list);
  }

}
